package com.ktgj.customer.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.io.IOException;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ktgj.customer.domain.vo.CaseMIne;
import com.ktgj.customer.domain.vo.TmpCaseMIneVo;
import com.ktgj.customer.domain.vo.TransferCountVo;
import com.ktgj.customer.domain.vo.TransferVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.CaseSys;
import com.ktgj.customer.service.ICaseSysService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 系统公用_工单Controller
 * 
 * @author ruoyi
 * @date 2022-03-03
 */
@RestController
@RequestMapping("/caseSys")
public class CaseSysController extends BaseController
{
    @Autowired
    private ICaseSysService caseSysService;

//    /**
//     * 查询系统公用_工单列表
//     */
//    @PreAuthorize(hasPermi = "customer:sys:list")
//    @GetMapping("/list")
//    public TableDataInfo list(CaseSys caseSys)
//    {
//        startPage();
//        List<CaseSys> list = caseSysService.selectCaseSysList(caseSys);
//        return getDataTable(list);
//    }
//
//    /**
//     * 导出系统公用_工单列表
//     */
//    @PreAuthorize(hasPermi = "customer:sys:export")
//    @Log(title = "系统公用_工单", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, CaseSys caseSys) throws IOException
//    {
//        List<CaseSys> list = caseSysService.selectCaseSysList(caseSys);
//        ExcelUtil<CaseSys> util = new ExcelUtil<CaseSys>(CaseSys.class);
//        util.exportExcel(response, list, "系统公用_工单数据");
//    }
//
//    /**
//     * 获取系统公用_工单详细信息
//     */
//    @PreAuthorize(hasPermi = "customer:sys:query")
//    @GetMapping(value = "/{caseId}")
//    public AjaxResult getInfo(@PathVariable("caseId") Long caseId)
//    {
//        return AjaxResult.success(caseSysService.selectCaseSysById(caseId));
//    }
//
//    /**
//     * 新增系统公用_工单
//     */
//    @PreAuthorize(hasPermi = "customer:sys:add")
//    @Log(title = "系统公用_工单", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody CaseSys caseSys)
//    {
//        return toAjax(caseSysService.insertCaseSys(caseSys));
//    }
//
//    /**
//     * 修改系统公用_工单
//     */
//    @PreAuthorize(hasPermi = "customer:sys:edit")
//    @Log(title = "系统公用_工单", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody CaseSys caseSys)
//    {
//        return toAjax(caseSysService.updateCaseSys(caseSys));
//    }
//
//    /**
//     * 删除系统公用_工单
//     */
//    @PreAuthorize(hasPermi = "customer:sys:remove")
//    @Log(title = "系统公用_工单", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{caseIds}")
//    public AjaxResult remove(@PathVariable Long[] caseIds)
//    {
//        return toAjax(caseSysService.deleteCaseSysByIds(caseIds));
//    }
    @PostMapping("/selectCaseMine")
    public TableDataInfo selectCaseMine(HttpServletRequest request, @RequestBody CaseMIne caseMIne) {
        startPage();
        List<TmpCaseMIneVo> tmpCaseMIneVoList;
        try {
            tmpCaseMIneVoList = caseSysService.selectCaseMine(caseMIne, request);
        } catch (Exception e){
            e.printStackTrace();
            List<TmpCaseMIneVo> tmpList = new ArrayList<>();
            TmpCaseMIneVo tmpCaseMIneVo = new TmpCaseMIneVo();
            tmpCaseMIneVo.setMsg(e.getMessage());
            tmpList.add(tmpCaseMIneVo);
            return getDataTable(tmpList);
        }
        return getDataTable(tmpCaseMIneVoList);
    }

    /**
     * 工单转移
     * */
    @PostMapping("/transferCount")
    public AjaxResult transferCount(HttpServletRequest request, @RequestBody TransferVo transferVo){
        List<TransferCountVo> transferCountVos;
        try {
            transferCountVos = caseSysService.transferCount(request, transferVo);
        } catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

        return AjaxResult.success(transferCountVos);
    }
}
